package com.lzh.jackson.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * @author zhehen.lu
 * @date 2025/8/13 10:01
 */
public class JacksonDoubleFloor2BitSerializer extends JsonSerializer<Double> {
    public JacksonDoubleFloor2BitSerializer() {
    }

    @Override
    public void serialize(Double aDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (aDouble == null) {
            jsonGenerator.writeNumber(0.0D);
        } else {
            jsonGenerator.writeNumber(Math.floor(aDouble * 100.0D) / 100.0D);
        }

    }
}
